1223B - Strings Equalization - CodeForces Solution


strings *1000

Please click on ads to support us..

Python Code:

for t in range(int(input())):
    print('NO' if len(set(input()) & set(input())) == 0 else 'YES')

C++ Code:

#include <bits/stdc++.h>
using namespace std;
const int N=1e7+10;
vector<int> spf(N,0);
void div(int N)
{
for(int i=2;i<N;i++)  // Least divisor
{
    if(spf[i]==0)
    {
        for(int j=i;j<N;j+=i)
        {
            if(spf[j]==0)
            spf[j]=i;
        }
    }
}
}
int fact(int n) 
{
   if (n == 0 || n == 1)
   return 1;
   else
   return n * fact(n - 1);
}
long long int combination(long long int n,long long int r)
{
    long long int comb;
    comb = fact(n) / (fact(r) * fact(n-r)); 
    return comb;
    
}
long long int perumation(long long int n,long long int r)
{
    long long int per = fact(n) / fact(n-r);
    return per;
    
}
void solve()
{
    int flag=0;
    string s;
    string t;
    cin>>s>>t;
    set<char> st;
    for(int i=0;i<s.size();i++)
    st.insert(s[i]);
    for(int i=0;i<s.size();i++)
    {
        if(st.find(t[i])!=st.end())
        {
            cout<<"YES"<<endl;flag=1;
            break;
        }
    }
    if(flag==0)
    cout<<"NO"<<endl;

}
int main()
{  
    int t;
    cin>>t;
    while(t--)
    {
        solve();
    }
   
    
}


Comments

Submit
0 Comments
More Questions

1084A - The Fair Nut and Elevator
1440B - Sum of Medians
1032A - Kitchen Utensils
1501B - Napoleon Cake
1584B - Coloring Rectangles
1562B - Scenes From a Memory
1521A - Nastia and Nearly Good Numbers
208. Implement Trie
1605B - Reverse Sort
1607C - Minimum Extraction
1604B - XOR Specia-LIS-t
1606B - Update Files
1598B - Groups
1602B - Divine Array
1594B - Special Numbers
1614A - Divan and a Store
2085. Count Common Words With One Occurrence
2089. Find Target Indices After Sorting Array
2090. K Radius Subarray Averages
2091. Removing Minimum and Maximum From Array
6. Zigzag Conversion
1612B - Special Permutation
1481. Least Number of Unique Integers after K Removals
1035. Uncrossed Lines
328. Odd Even Linked List
1219. Path with Maximum Gold
1268. Search Suggestions System
841. Keys and Rooms
152. Maximum Product Subarray
337. House Robber III